/**
 * Created by sfr on 2017/10/10.
 */
import React from "react";
import { routerRedux } from 'dva/router';
import {connect} from "dva";
import moment from 'moment';
import {Tabs, Flex, List, WhiteSpace, Carousel, Icon} from "antd-mobile";
import styles from './workLog.less'
const empty = require('is-empty');
const Item = List.Item;
const Brief = Item.Brief;
const TabPane = Tabs.TabPane;


class WorkLog extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data:'',
    };
  }

  componentWillReceiveProps=(nextProps)=>{
    console.log(nextProps,'nextPropsnextPropsnextProps')
    const {workLog}=nextProps
    const {data}=workLog
    console.log(data[0],'workLog 的data数据')
    this.setState({
      data:data[0]
    })
  }

  onClick=(str)=>{
    // this.props.dispatch(
    //   routerRedux.push({
    //     pathname: `/work/workLog/workDetails`,
    //     query: {
    //       id:str
    //     }
    //   })
    // )
  };
  //审核中 查看详情
  reviewClick=(Code,str)=>{
    this.props.dispatch(
      routerRedux.push({
        pathname: `/work/workLog/workDetails`,
        query: {
          i:Code,
          id:str
        }
      })
    )
  }


  //table点击函数
  handleTabClick = (key) => {
    if (key==1){
      console.log('11111111111', key);
      this.props.dispatch({
        type:'workLog/getTask',
        payload:{
          code:'workLog',
          pagination:false,
          para:[{key:'art_type',values:[3]},{key:'status',values:[0]}],
        }
      });
    }else if(key==2){
      console.log('22222222222', key);
      this.props.dispatch({
        type:'workLog/getTask',
        payload:{
          code:'workLog',
          pagination:false,
          para:[{key:'art_type',values:[3]},{key:'status',values:[1]}],
        }
      });
    }else if(key==3){
      console.log('22222222222', key);
      this.props.dispatch({
        type:'workLog/getTask',
        payload:{
          code:'workLog',
          pagination:false,
          para:[{key:'art_type',values:[3]},{key:'status',values:[2]}],
        }
      });
    }
  }
  //点击添加
  handleAdd = () => {
    this.props.dispatch(
      routerRedux.push({
        pathname: `/work/workLog/workAdd`,
        query: {}
      })
    );
  }
  //==生命周期--页面渲染
  render() {
    const workData=this.props.workLog.data
    return (
      <div className='workLog' style={{backgroundColor:'#fff'}}>
				{/*tab*/}
        <Tabs
					defaultActiveKey="1"
					animated={true}
					swipeable={false}
					onTabClick={this.handleTabClick}>
					<Tabs.TabPane tab="审核中" key="1">
						<div>
							{/*顶部空白，由于tabs固定不变*/}
							<div className={styles.tabsBlank}></div>
							{/*具体的发布第一条*/}
              {!empty(workData)&&
              workData.map((it,index)=>{
                  return(
                    <div className={styles.releaseBox} key={index}  onClick={()=>this. reviewClick(it.Code,'examine')}>
                      <Item multipleLine>{it.art_title}<Brief>{it.art_content}</Brief></Item>
                    </div>
                  )
                })
              }
						</div>
					</Tabs.TabPane>
					<Tabs.TabPane tab="已通过" key="2">
						<div>
							{/*顶部空白，由于tabs固定不变*/}
							<div className={styles.tabsBlank}></div>
							{/*具体的发布第一条*/}
              {/*{*/}
               {/*[1,2,3,4].map((key)=>{*/}
                 {/*return(*/}
                   {/*<div className={styles.releaseBox} key={key} onClick={()=>this.onClick('adopt')}>*/}
                       {/*<Item multipleLine>赴乌鲁木齐市网信办调研督导 <Brief>9月30日到乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市</Brief></Item>*/}
                       {/*<Item multipleLine>赴乌鲁木齐市网信办调研督导 <Brief>9月30日到乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市</Brief></Item>*/}
                       {/*<Item multipleLine>赴乌鲁木齐市网信办调研督导 <Brief>9月30日到乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市</Brief></Item>*/}
                       {/*<Item multipleLine>赴乌鲁木齐市网信办调研督导 <Brief>9月30日到乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市乌鲁木齐市</Brief></Item>*/}
                   {/*</div>*/}
                 {/*)*/}
               {/*})*/}
              {/*}*/}

              {!empty(workData)&&
              workData.map((it,index)=>{
                return(
                  <div className={styles.releaseBox} key={index}  onClick={()=>this. reviewClick(it.Code,'adopt')}>
                    <Item multipleLine>{it.art_title}<Brief>{it.art_content}</Brief></Item>
                  </div>
                )
              })
              }
						</div>
					</Tabs.TabPane>
					<Tabs.TabPane tab="未通过" key="3">
						<div>
							{/*顶部空白，由于tabs固定不变*/}
							<div className={styles.tabsBlank}></div>
							{/*具体的发布第一条*/}
              {/*{*/}
                {/*[1,2,3,4].map((key)=>{*/}
                  {/*return(*/}
                    {/*<div className={styles.releaseBox} key={key}  onClick={()=>this.onClick('fail')}>*/}
                      {/*<div className={styles.releaseTitle}>赴乌鲁木齐市网信办调研督导</div>*/}
                      {/*<div className={styles.releaseContent}>9月30日到乌鲁木齐市网信办开展党建工作督导</div>*/}
                    {/*</div>*/}
                  {/*)*/}
                {/*})*/}
              {/*}*/}
              {!empty(workData)&&
              workData.map((it,index)=>{
                return(
                  <div className={styles.releaseBox} key={index}  onClick={()=>this. reviewClick(it.Code,'fail')}>
                    <Item multipleLine>{it.art_title}<Brief>{it.art_content}</Brief></Item>
                  </div>
                )
              })
              }
						</div>
					</Tabs.TabPane>
				</Tabs>
        {/*底部添加按钮*/}
        <div className={styles.add} onClick={this.handleAdd}>
          <Icon type={require('../../../svgs/news/pen.svg')}  className={styles.addIcon}/>
        </div>
      </div>
    );
	}

}

function mapStateToProps({ information,workLog }){
  return {
    information,
    workLog
	};
}
export default connect(mapStateToProps)(WorkLog);


